package com.example.administrator.hellocomp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Toast;

import java.io.File;
import java.io.IOException;

public class MyReceiver2 extends BroadcastReceiver {

    MediaRecorder recorder ;
    File sdpath  = Environment.getExternalStorageDirectory();


    @Override
    public void onReceive(Context context, Intent intent) {

        if(intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL"))
        {
//            recorder = new MediaRecorder();
//
//            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
//            recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
//            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
//            recorder.setOutputFile(sdpath.toString()+"/Music/recorder/"+System.currentTimeMillis()+".amr");

            String phoneNum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            Toast.makeText(context,"监听到拨打电话："+phoneNum,Toast.LENGTH_SHORT).show();


            Intent intent2 = new Intent(context,recorderService.class);
            Bundle bundle = new Bundle();
            int op = 0;
            bundle.putInt("op",op);
            intent2.putExtras(bundle);
            context.startService(intent2);
//            Toast.makeText(context,"已经发送广播到服务："+op,Toast.LENGTH_SHORT).show();
//            final File sdpath;
//            try{
//
//                recorder.prepare();
//                recorder.start();
//
//            }catch (IOException er)
//            {
//                er.printStackTrace();
//            }
//            startActivityForResult(intent, 100);




        }


    }
}
